package wangjg.mda.tra;

import java.util.List;
import java.util.Map;

import wangjg.mda.model.obj.Method;
import wangjg.mda.model.obj.Model;
import wangjg.mda.model.obj.ModelDataType;
import wangjg.mda.model.obj.ModelField;

public class MvcUtil {

	public List<ModelField> getParamFields(Model model) {
		
		return null;
	}
	
	public List<ModelField> getRefParamFields(Model model) {
		
		return null;
	}
	
	public String getAction(Method method){
		if(method.getAttributes()!=null){
			Object reqMap = method.getAttributes().get("RequestMapping");
			if(reqMap!=null && Map.class.isAssignableFrom(reqMap.getClass())){
				Map map = (Map)reqMap;
				Object value = map.get("value");
				return (String)value;	
			}
		}
		return null;
	}
	
	public String getDbType(ModelField field){
		if(ModelDataType.STRING.equals(field.getType())){
			if(field.getLength()==1){
				return ModelDataType.CHAR;
			}
		}
		return field.getType();
	}

	public int getDbLength(ModelField field){
		if(ModelDataType.STRING.equals(field.getType())){
			if(field.getLength()==null){
				return 255;
			}
		}
		return field.getLength();
	}
	
}
